<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>角色权限</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="/system_assets/css/bootstrap.min.css" rel="stylesheet">
	<link href="/system_assets/css/style.css" rel="stylesheet">
	<link href="/system_assets/css/font-awesome.css" rel="stylesheet">
</head>
<body>
	<div class="container-fluid">
		<div class="om-ctl-mes">
			<div class="title">
				<div class="col-xs-12"><span class="fa fa-list-ul"> 系统设置</span><b class="fa fa-caret-right"></b><i>角色权限</i></div>
			</div>
			
			 <div class="personset-content col-xs-12">
                <div id="personset-tab-list" class="tab-title">
                   <span data='1' class='role' style="background:#fff;" b="1">超级管理员</span>
                   <span data='2' class='role'>管理员</span>
                   <span data='3' class='role'>院长</span>
                   <span data='4' class='role'>诊室</span>
                   <span data='5' class='role'>后勤</span>
                   <span data='6' class='role'>器械</span>
                   <span data='7' class='role'>护工</span>
                   <span data='8' class='role'>督导</span>
                   <span data='9' class='role'>厨师</span>
                   <span data='10' class='role'>财务</span>
              </div>
              <div id="personset-tab-content">
              	   <!-- 超级管理员 -->
                <div>
                    <form data='1'>
                 <article>
                  <table class="table off-table role-tabel">
	              <thead>
	             	<tr>
			        <th>全选</th>
			        <th>功能</th>
			        <th>权限</th>
		            </tr>
	              </thead>
	             <tbody>
                    <tr>
                    <td><input type="checkbox" class="checkAll" name="permission[]" value="28" id="28" <?if(in_array('28',explode(',',$tPRow['permission'])))echo 'checked';?>></td>
                    	<td><label for="28">老人管理</label></td>
                    	<td>
                    	<div class="checklist">
						<div><input type="checkbox" name="permission[]" value="1" id="1"<?if(in_array('1',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="1">老人信息</label></div>
						<div><input type="checkbox" name="permission[]" value="7" id="7"<?if(in_array('7',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="7">老人用药</label></div>
						<div><input type="checkbox" name="permission[]" value="8" id="8"<?if(in_array('8',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="8">日常护理</label></div>
						<div><input type="checkbox" name="permission[]" value="9" id="9"<?if(in_array('9',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="9">离院管理</label></div>
					    </div>
                    	</td>
                    </tr>
                    <tr>
                    	<td><input type="checkbox" name="permission[]" value="29" id="29"<?if(in_array('29',explode(',',$tPRow['permission'])))echo 'checked';?>></td>
                    	<td><label for="29">配餐&配货管理</label></td>
                    	<td>
                    	<div class="checklist">
						<div><input type="checkbox" name="permission[]" value="10" id="10"<?if(in_array('10',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="10">配餐记录</label></div>
						<div><input type="checkbox" name="permission[]" value="15" id="15"<?if(in_array('15',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="15">配货记录</label></div>
						<div><input type="checkbox" name="permission[]" value="16" id="16"<?if(in_array('16',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="16">申请报修</label></div>
					    </div>
                    	</td>
                    </tr>
                    <tr>
                    	<td><input type="checkbox" name="permission[]" value="30" id="30"<?if(in_array('30',explode(',',$tPRow['permission'])))echo 'checked';?>></td>
                    	<td><label for="30">督导管理</label></td>
                    	<td>
                    	<div class="checklist">
						<div><input type="checkbox" name="permission[]" value="12" id="12"<?if(in_array('12',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="12">部门情况列表</label></div>
						<div><input type="checkbox" name="permission[]" value="13" id="13"<?if(in_array('13',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="13">督查评分详情</label></div>
					    </div>
                    	</td>
                    </tr>
                    <tr>
                    	<td><input type="checkbox" name="permission[]" value="32" id="32"<?if(in_array('32',explode(',',$tPRow['permission'])))echo 'checked';?>></td>
                    	<td><label for="32">员工管理</label></td>
                    	<td>
                    	<div class="checklist">
						<div><input type="checkbox" name="permission[]" value="2" id="2"<?if(in_array('2',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="2">员工记录</label></div>
						<div><input type="checkbox" name="permission[]" value="3" id="3"<?if(in_array('3',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="3">培训记录</label></div>
						<div><input type="checkbox" name="permission[]" value="4" id="4"<?if(in_array('4',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="4">请假记录</label></div>
						<div><input type="checkbox" name="permission[]" value="5" id="5"<?if(in_array('5',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="5">考核记录</label></div>
						<div><input type="checkbox" name="permission[]" value="6" id="6"<?if(in_array('6',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="6">离职记录</label></div>
					    </div>
                    	</td>
                    </tr>
                    <tr>
                    	<td><input type="checkbox" name="permission[]" value="33" id="33"<?if(in_array('33',explode(',',$tPRow['permission'])))echo 'checked';?>></td>
                    	<td><label for="33">财务管理</label></td>
                    	<td>
                    	<div class="checklist">
						<div><input type="checkbox" name="permission[]" value="17" id="17"<?if(in_array('17',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="17">员工工资</label></div>
						<div><input type="checkbox" name="permission[]" value="18" id="18"<?if(in_array('18',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="18">老人缴费结算</label></div>
						<div><input type="checkbox" name="permission[]" value="19" id="19"<?if(in_array('19',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="19">老人出院结算</label></div>
					    </div>
                    	</td>
                    </tr> 
                     <tr>
                    	<td><input type="checkbox" name="permission[]" value="34" id="34"<?if(in_array('34',explode(',',$tPRow['permission'])))echo 'checked';?>></td>
                    	<td><label for="34">后勤管理</label></td>
                    	<td>
                    	<div class="checklist">
						<div><input type="checkbox" name="permission[]" value="20" id="20"<?if(in_array('20',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="20">采购清单</label></div>
						<div><input type="checkbox" name="permission[]" value="21" id="21"<?if(in_array('21',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="21">配送清单</label></div>
						<div><input type="checkbox" name="permission[]" value="22" id="22"<?if(in_array('22',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="22">医疗器械</label></div>
					    </div>
                    	</td>
                    </tr>
                     <tr>
                    	<td><input type="checkbox" name="permission[]" value="35" id="35"<?if(in_array('35',explode(',',$tPRow['permission'])))echo 'checked';?>></td>
                    	<td><label for="35">系统设置</label></td>
                    	<td>
                    	<div class="checklist">
						<div><input type="checkbox" name="permission[]" value="23" id="23"<?if(in_array('23',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="23">医药库</label></div>
						<div><input type="checkbox" name="permission[]" value="24" id="24"<?if(in_array('24',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="24">全局设置</label></div>
						<div><input type="checkbox" name="permission[]" value="25" id="25"<?if(in_array('25',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="25">账号管理</label></div>
						<div><input type="checkbox" name="permission[]" value="26" id="26"<?if(in_array('26',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="26">角色权限</label></div>
						<div><input type="checkbox" name="permission[]" value="27" id="27"<?if(in_array('27',explode(',',$tPRow['permission'])))echo 'checked';?>><label for="27">分院管理</label></div>
					    </div>
                    	</td>
                    </tr>
	            </tbody>
              </table>
                  </article>
                </form>
                </div>
  <!-- 管理员 -->
                <div>
                <form data='2'>
                  <article>
                  </article>
                </form>
                </div>
  <!-- 院长 -->
                <div>
                <form data='3'>
                  <article>
                  </article>
                </form>
                </div>
                
  <!-- 诊室 -->
                <div>
                <form data='4'>
                  <article>
                  </article>              
                </form>
                <div>
  <!-- 后勤 -->
                <div>
                <form data='5'>
                  <article>
                  </article>
                </form>
                </div>
  <!-- 器械 -->
                <div>
                <form data='6'>
                  <article>
                  </article>
                </form>
                </div>
  <!-- 护工 -->
                <div>
                <form data='7'>
                  <article>
                  </article>
                </form>
                </div>
  <!-- 督导 -->
                <div>
                <form data='8'>
                  <article>
                  </article>
                </form>
                </div>
  <!-- 厨师 -->
                <div>
                <form data='9'>
                  <article>
                  </article>
                </form>
                </div>
  <!-- 财务 -->
                <div>
                <form data='10'>
                  <article>
                  </article>
                </form>
                </div>

               </div>
		</div>
    </div>
     <script type="text/javascript" src="/system_assets/js/jquery.min.js"></script>
        <script type="text/javascript" src="/system_assets/js/personset-jq.js"></script>
        <script type="text/javascript">
              $(function(){
           $(".role-tabel tbody tr td").find('input').click(function(){

            if($(this).is(":checked")){
                $(this).parent().parent().find('td').eq(2).find('.checklist').find('input').each(function(){
                    this.checked=true;    
                });
            }else{
                $(this).parent().parent().find('td').eq(2).find('.checklist').find('input').each(function(){
                    this.checked=false;    
                });
            }
            })

           /*$('.checklist div input').click(function(){
                $(this).parent().parent().parent().parent().find('td').eq(0).find('input').prop("checked",false)
              })*/
         })
         $('.role').each(function(){
            $(this).click(function(){
                var role = $(this).attr('data');
                $.post('/admin_permission',{ role_id:role },function(obj){
                    var data = obj.data;
                    $('input[type="checkbox"]').removeAttr('checked');
                    $('input[type="checkbox"]').each(function(){
                        var arr = data.permission.split(',');
                        if(arr.indexOf($(this).val()) > -1){
                            $(this).attr('checked','checked');
                        }
                    });
                });
            });
         });
         var data = '';
         var s = '';

         $('.role').each(function(){
            $(this).click(function(){
            $('.role').removeAttr('b');
                $(this).attr('b',1);
            });
         });
            $('span[b="1"]').click(function(){
                var role = $(this).attr('data');
                $('input[type="checkbox"]').click(function(){
                    var s = $('form[data="1"]').serialize();
                    data = s+'&role='+role;
                });
                $(document).keyup(function(event){
                    if(event.keyCode ==13){
                        // $("#submit").trigger("click");
                        $.post('/admin_permission/',data,function(obj){
                            if(role == ''){
                                alert('请先选择角色');return;
                            }
                            alert(obj.msg);location.href="/admin_permission";return; 
                        });
                    }
                });
            });
         var role = $('span[b="1"]').attr('data');
         $('input[type="checkbox"]').click(function(){
            var s = $('form[data="1"]').serialize();
            data = s+'&role='+role;
         });
         /*$('input[type="checkbox"]').each(function(){
            $(this).click(function(){
                s = $('form[data="1"]').serialize();
                data = s+'&role='+role;
            });
         });*/
         $(document).keyup(function(event){
            if(event.keyCode == 13){
                $.post('/admin_permission/',data,function(obj){
                    alert(obj.msg);location.href="/admin_permission";
                });
            }
         });
        </script>
</body>
</html>
